package com.ftg.learn.util;


import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * filter token全拦截
 * @author 布衣
 */
@Data
@Schema(name="前后台交互统一封装类")
@NoArgsConstructor
@AllArgsConstructor
public class R<T> {

    @Schema(name="状态码,200表示成功")
    private Integer code;
    @Schema(name="提示信息")
    private String msg;
    @Schema(name="影响数据")
    private T data;

    public static <T> R<T> ok() {
        return new R<T>(200, "操作成功", null);
    }

    public static <T> R<T> failure() {
        return new R<T>(500, "操作失败", null);
    }

    public static <T> R<T> ok(T data) {
        return new R<T>(200, "操作成功", data);
    }

    public static <T> R<T> failure(String msg) {
        return new R<T>(500, msg, null);
    }

    public static <T> R<T> build(Integer code,String msg,T Data) {
        return new R<T>(code, msg, Data);
    }

}
